package com.xijia.proxy.service;

import com.xijia.proxy.service.cglib.CglibMethodInterceptor;
import com.xijia.proxy.service.impl.MemberServiceImpl;
import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.proxy.Enhancer;


/**
 * 使用cglib 示例
 * @author wangsong
 * @mail 1720696548@qq.com
 * @date 2020/8/30 0030 18:32
 * @version 1.0.0
 */
public class Test2 {
    public static void main(String[] args) {
        // 保存class 文件到-->
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "D:\\code");
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(MemberServiceImpl.class);
        enhancer.setCallback(new CglibMethodInterceptor());
        // 创建代理代理对象
        MemberService memberService = (MemberService) enhancer.create();
        String res = memberService.addMember("1720696548");
        System.out.println("----> cglib动态代理返回数据为：" + res);
    }
}
